﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Objects;
using System.Collections.Generic;
using BAL;

public partial class Admin_UCControls_KhachHang_Update : System.Web.UI.UserControl
{
    private static KhachHang ItemKhachHang;
    private static DangKy ItemDangKy;

    public static string srtPath;
    

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //GetTinhThanh();
          
            ItemKhachHang = new KhachHang();
            ItemKhachHang = (KhachHang)Session["ItemKhachHang"];

            if (ItemKhachHang != null)
            {
                GetThongtinKhachHang(ItemKhachHang);
                GetThongTinDangKy(ItemKhachHang.Id);
                if (ItemDangKy != null)
                {
                    GetThongTinKhachHangTrenThe(ItemDangKy.IdKhachHangNhanThe);
                    GetThongTinKhachHangNhanThe(ItemDangKy.IdKhachHangNhanTheKhac);
                    GetDuyet(ItemDangKy.Id);
                }

            }
           
        }
    }

    public void GetDuyet(int idDangKy)
    {
        if (idDangKy > 0)
        {
            Duyet itemDuyet = new Duyet();
            itemDuyet = BALDuyet.GetByIdDangKy(idDangKy);

            lblNgayDuyet.Text = itemDuyet.NgayDuyet.ToShortDateString();

            if (itemDuyet.TrangThaiDuyet == 0)
            {
                lblTrangThaiDuyet.Text = "Chờ duyệt";
            }
            else if (itemDuyet.TrangThaiDuyet == 1)
            {
                lblTrangThaiDuyet.Text = "Duyệt";
            }
            else
            {
                lblTrangThaiDuyet.Text = "Không duyệt";
            }

            if (itemDuyet.IdNguoiDung > 0)
            {
                NguoiDung itemNguoiDung = new NguoiDung();
                itemNguoiDung = BALNguoiDung.GetById(itemDuyet.IdNguoiDung);
                lblNguoiDuyet.Text = itemNguoiDung.TenNguoiDung.ToString();
            }
        }
    }

    public void GetThongtinKhachHang(KhachHang khachHang)
    {
            lblHoTen.Text = khachHang.Ten.ToString();
            lblNgaySinh.Text = khachHang.NgaySinh.ToString("dd/MM/yyyy");
            lblSoDienThoai.Text = khachHang.DienThoaiNha.ToString();
            lblCMND.Text = khachHang.CMND.ToString();
            lblDiachi.Text = khachHang.DiaChiLienLac.ToString();
            lblDiaChiThuongTru.Text = khachHang.DiaChiThuongTru.ToString();
            lbldtdd.Text = khachHang.DienThoaiDiDong.ToString();
            lblEmail.Text = khachHang.Email.ToString();
            if (khachHang.GioiTinh.ToString() == "2")
            {
                lblGioitinh.Text = "Nữ";
            }
            else
            {
                lblGioitinh.Text = "Nam";
            }
        
    }

    public void GetThongTinDangKy(int idKhachHang)
    {
        ItemDangKy = new DangKy();
        ItemDangKy = BALDangKy.GetByIdKhachHang(idKhachHang);

        if (ItemDangKy != null)
        {

            lblSoLuong.Text = ItemDangKy.SoLuong + "";
            lblNgayDangKy.Text = ItemDangKy.NgayDangKy.ToShortDateString();
            lblNgayNhanThe.Text = ItemDangKy.NgayNhanThe.ToShortDateString();
            lblHetHan.Text = ItemDangKy.NgayHetHan.ToShortDateString();

            LoaiThe ItemLoaiThe = new LoaiThe();
            ItemLoaiThe = BALLoaiThe.GeById(ItemDangKy.IdLoaiThe);
            lblLoaiThe.Text = ItemLoaiThe.LoaiTheDK.ToString();

            MauThe ItemMauThe = new MauThe();
            ItemMauThe = BALMauThe.GetById(ItemDangKy.IdMauThe);
            lblMauThe.ImageUrl = PathImage() + ItemMauThe.DuongDan.ToString();

            ChuDe ItemChuDe = new ChuDe();
            ItemChuDe = BALChuDe.GetByIdChuDe(ItemMauThe.IdChuDe);
            lblChuDe.Text = ItemChuDe.TenChuDe.ToString();

            if (ItemDangKy.IdMenhGia > 0)
            {
                MenhGia ItemMenhGia = new MenhGia();
                ItemMenhGia = BALMenhGia.GetById(ItemDangKy.IdMenhGia);
                lblMenhGia.Text = ItemMenhGia.LoaiMenhGia.ToString();
            }

            if (ItemDangKy.IdMenhGiaKhac > 0)
            {
                MenhGiaKhac ItemMenhGiaKhac = new MenhGiaKhac();
                ItemMenhGiaKhac = BALMenhGiaKhac.GetById(ItemDangKy.IdMenhGiaKhac);
                lblMenhGia.Text = ItemMenhGiaKhac.LoaiMenhGia.ToString();
            }

            double thanhtien = Convert.ToInt64(lblSoLuong.Text) * Convert.ToInt64(lblMenhGia.Text);
            lblThanhTien.Text = thanhtien + " VND";

            if (ItemDangKy.IdPhuongThucThanhToan > 0)
            {
                PhuongThucThanhToan itemPhuongThucThanhToan = new PhuongThucThanhToan();
                itemPhuongThucThanhToan = BALPhuongThucThanhToan.GetById(ItemDangKy.IdPhuongThucThanhToan);
                lblPTTT.Text = itemPhuongThucThanhToan.HinhThuc.ToString();
            }

            if (ItemDangKy.IdChiNhanh > 0)
            {
                ChiNhanh itemChiNhanh = new ChiNhanh();
                itemChiNhanh = BALChiNhanh.GetById(ItemDangKy.IdChiNhanh);
                lblChiNhanh.Text = itemChiNhanh.Ten.ToString();
            }
        }
    }

    public string PathImage()
    {
        return srtPath = "~/images/Generic Card/";
    }

    public void GetThongTinKhachHangTrenThe(int idKhachHang)
    {
        if (idKhachHang > 0)
        {

            KhachHangNhanThe ItemKhachHangNhanThe = new KhachHangNhanThe();
            ItemKhachHangNhanThe = BALKhachHangNhanThe.GetById(idKhachHang);
            lblHotenTrenThe.Text = ItemKhachHangNhanThe.Ten.ToString();
            lblNgaysinhTrenThe.Text = ItemKhachHangNhanThe.NgaySinh.ToShortDateString();
            if (ItemKhachHangNhanThe.GioiTinh.ToString() == "2")
            {
                lblGioiTinhTrenThe.Text = "Nữ";
            }
            else
            {
                lblGioiTinhTrenThe.Text = "Nam";
            }
            lblSoDienThoai.Text = ItemKhachHangNhanThe.DienThoaiNha.ToString();
            lblCMNDTrenThe.Text = ItemKhachHangNhanThe.CMND.ToString();
            lbldiaChiLLTrenThe.Text = ItemKhachHangNhanThe.DiaChiLienLac.ToString();
            lblDCTTrenThe.Text = ItemKhachHangNhanThe.DiaChiThuongTru.ToString();
            lblDTDDrenThe.Text = ItemKhachHangNhanThe.DienThoaiDiDong.ToString();
            lblEmailTrenThe.Text = ItemKhachHangNhanThe.Email.ToString();
        }

    }

    public void GetThongTinKhachHangNhanThe(int idkhachhang)
    {
        if (idkhachhang > 0)
        {
            KhachHangNhanTheKhac itemKhachHangTrenTheKhac = new KhachHangNhanTheKhac();
            itemKhachHangTrenTheKhac = BALKhachHangNhanTheKhac.GetById(idkhachhang);

            lblNguoiNhan.Text = itemKhachHangTrenTheKhac.NguoiNhan.ToString();
            lblDiaChi2.Text = itemKhachHangTrenTheKhac.DiaChi.ToString();
            lblSoDienThoai2.Text = itemKhachHangTrenTheKhac.SoDienThoai.ToString();
            lblThongDiep.Text = itemKhachHangTrenTheKhac.ThongDiep.ToString();
        }
    }


}
